package com.baizhi.controller;

import com.baizhi.dto.PageDTO;
import com.baizhi.entity.Video;
import com.baizhi.service.VideoService;
import com.baizhi.vo.CommonMessageVO;
import com.baizhi.vo.CommonVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@CrossOrigin
@RequestMapping("video")
public class VideoController {

    @Resource
    private VideoService videoService;

    private static final Logger log = LoggerFactory.getLogger(VideoController.class);

    /**
     * 分页查所有
     */
    @PostMapping("queryAllPage")
    public CommonVO queryAllPage(@RequestBody PageDTO pageDTO){
        log.info("pageDTO :{}",pageDTO);
        //查所有
        CommonVO commonVO = videoService.page(pageDTO);
        return commonVO;
    }
    /**
     * 添加视频
     */
    @PostMapping("uploadHeadImg")
    public void uploadHeadImg(MultipartFile videoFile){
        log.info("videoFile:{}",videoFile.getOriginalFilename());
        videoService.uploadHeadImg(videoFile);
    }
    /**
     * 添加视频
     */
    @PostMapping("add")
    public CommonMessageVO add(@RequestBody Video video){
        log.info("video : {}",video);
        CommonMessageVO add = videoService.add(video);
        return add;
    }
    @PostMapping("update")
    public CommonMessageVO update(@RequestBody Video video){
        log.info("video : {}",video);
        CommonMessageVO update = videoService.update(video);
        return update;
    }

    @GetMapping("queryById")
    public Video queryById(Video video){
        log.info("video : {}",video);
        Video videos = videoService.queryById(video);
        return videos;
    }

    //删除
    @PostMapping("delete")
    public CommonMessageVO delete(@RequestBody Video video){
        log.info("video : {}",video);
        CommonMessageVO delete = videoService.delete(video);
        return delete;
    }
}
